extends StateBase

var enemy:Enemy01

func enterState(ownerNode):
	enemy = ownerNode as Enemy01
	
	var player = get_tree().get_first_node_in_group("Player") as PlayerScript
	var distance2Player = player.global_position.distance_to(enemy.global_position)
	var dir = sign(player.global_position.x - enemy.global_position.x) 
	
	enemy.velocity.y = enemy.HIT_VELOCITY_Y
	enemy.velocity.x = enemy.HIT_VELOCITY_X * -dir
	
	enemy.animationPlayerShader.play("HitFlash")
	
	
func exitState(ownerNode):
	pass
	
	
func process(delta, ownerNode):
	pass
	
	
func physicsProcess(delta, ownerNode):
	enemy.animations.play("Idle")
	
	enemy.velocity.y += enemy.gravity * enemy.gravityScale * delta
	
	enemy.move_and_slide()
	
	if enemy.is_on_floor():
		if enemy.health <= 0:
			stateMachine.changeState("StateDead", ownerNode)
		else:
			stateMachine.changeState("StateIdle", ownerNode)
		
	
